/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2024-03-21 13:59:44
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-04-22 19:05:38
 * @FilePath: /yt-devops/lib/pages/mine/system_set/security/security_controller.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:bruno/bruno.dart';
import 'package:get/get.dart';
import 'package:yt_devops/configs.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/routers/router_path.dart';
import 'package:yt_devops/services/auth/auth_services.dart';
import 'package:yt_devops/user_entity_manager.dart';

class SecurityController extends GetxController {
  AuthServices authServices = AuthServices();
  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onReady() {}

  @override
  void onClose() {}

  void toNextPage(int index) {
    if (index == 1) {
      BrnDialogManager.showConfirmDialog(Get.context!,
          cancel: ResKey.cancel.tr,

          confirm: ResKey.confirmLogout.tr,
          title: ResKey.accountCancellationReminder.tr,
          message: ResKey.logoutResult.tr,

          onCancel: () => Get.back(),
          onConfirm: () {
            Get.back();
            cancelAccount();
          });
    } else {
      Get.toNamed(RouterPath.changePassword);
    }
  }

  cancelAccount() => Configs.httpClient.requestWithLoading(() async {
        await authServices.updateStatusByUserId({
          "status": "1",
          "userId": UserEntityManager().userModel.userId,
        });
        await UserEntityManager().cleanAuth();
        Get.offAllNamed(RouterPath.login);
      });
}
